
/*
 * 石头剪刀布 游戏
 * - 传入用户的操作，随机一个电脑的操作，进行比较，返回结果
 */
module.exports = function(playerAction) {
    let random = Math.random() * 3;  // (0, 3)
    let computerAction = 'rock'
    if (random < 1) {
        computerAction = 'scissor'
    }else if (random > 2) {
        computerAction = 'paper'
    }

    if (computerAction === playerAction) { //平局
        return 0
    }else if (
        (computerAction === 'rock' && playerAction === 'paper') ||
        (computerAction === 'paper' && playerAction === 'scissor') || 
        (computerAction === 'scissor' && playerAction === 'rock')
    ) { // 用户赢
        return -1
    }else { // 电脑赢
        return 1
    }
}